package com.levi.controller;

import com.levi.client.ProductClient;
import com.levi.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shentong
 * @since 2022/6/12 11:41 AM
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Resource
    private OrderService orderService;

    @Resource
    private ProductClient productClient;


    @GetMapping("create")
    @GlobalTransactional
    public boolean create(@RequestParam Integer productId,
                            @RequestParam Integer count){
        orderService.create(productId, count);
        productClient.decut(productId, count);
        return true;
    }
}
